/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.model;

import java.math.BigDecimal;
import java.util.Calendar;

import lt.marsrutai.mobile.android.model.enums.DateTime;
import android.os.Parcel;
import android.os.Parcelable;

public class SegmentPoint implements Parcelable {
    
    public static final Parcelable.Creator<SegmentPoint> CREATOR = new Parcelable.Creator<SegmentPoint>() {

        @Override
        public SegmentPoint createFromParcel(Parcel in) {
            return new SegmentPoint(in);
        }

        @Override
        public SegmentPoint[] newArray(int size) {
            return new SegmentPoint[size];
        }
    };
    
    private BigDecimal latitude;
    private BigDecimal longitude;

    private String stopId;
    private String stopName;
    private String stopDirectionName;
    
    private Calendar time;

    public SegmentPoint() {
    }
    
    public SegmentPoint(Parcel in) {
        if (in.readInt() == 1) {
            longitude = new BigDecimal(in.readDouble());
        }
        if (in.readInt() == 1) {
            latitude = new BigDecimal(in.readDouble());
        }
        
        stopId = in.readString();
        stopName = in.readString();
        stopDirectionName = in.readString();

        if (in.readInt() == 1) {
            time = new DateTime(in.readLong()).getCalendar();
        }      
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (longitude == null) {
            dest.writeInt(0);
        }
        else {
            dest.writeInt(1);
            dest.writeDouble(longitude.doubleValue());
        }
        
        if (latitude == null) {
            dest.writeInt(0);
        }
        else {
            dest.writeInt(1);
            dest.writeDouble(latitude.doubleValue());
        }

        dest.writeString(stopId);
        dest.writeString(stopName);
        dest.writeString(stopDirectionName);
        
        if (time == null) {
            dest.writeInt(0);
        }
        else {
            dest.writeInt(1);
            dest.writeLong(time.getTimeInMillis());
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public BigDecimal getLatitude() {
        return latitude;
    }

    public void setLatitude(BigDecimal latitude) {
        this.latitude = latitude;
    }

    public BigDecimal getLongitude() {
        return longitude;
    }

    public void setLongitude(BigDecimal longitude) {
        this.longitude = longitude;
    }

    public String getStopId() {
        return stopId;
    }

    public void setStopId(String stopId) {
        this.stopId = stopId;
    }

    public String getStopName() {
        return stopName;
    }

    public void setStopName(String stopName) {
        this.stopName = stopName;
    }

    public String getStopDirectionName() {
        return stopDirectionName;
    }

    public void setStopDirectionName(String stopDirectionName) {
        this.stopDirectionName = stopDirectionName;
    }

    public Calendar getTime() {
        return time;
    }

    public void setTime(Calendar time) {
        this.time = time;
    }
}
